package com.skycong.hello77.activity.intent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.skycong.hello77.R;


/**
 * 第一个页面
 * Created by Kiki on 2018/5/17.
 */

public class FirstPageActivity extends Activity implements View.OnClickListener{
    public Button button;
    public TextView textView;
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_checkbox);
        button = (Button) findViewById(R.id.button1);
        textView = (TextView) findViewById(R.id.text1);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.button1){
            Intent intent  = new Intent(FirstPageActivity.this,SecondPageActivity.class);
            /*
            * 第一个参数是请求的Intent对象
            * 第二个参数是请求的一个标识
            * */
            startActivityForResult(intent,1);
        }
    }

    /**
     * startActivityForResult跳转，接受返回数据的方法
     * @param requestCode 请求的标识
     * @param resultCode 那个页面返回的标识
     * @param data 那个界面返回的数据
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 1 && resultCode == 2){
            String aa = data.getStringExtra("data");
            textView.setText(aa);
        }
    }
}
